//
//  PhotoCollectionViewCell.m
//  时尚男士
//
//  Created by dlios on 15-6-11.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "PhotoCollectionViewCell.h"

@implementation PhotoCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 滚动视图
        self.myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.bounds.size.width, self.contentView.bounds.size.height)];
        self.myScrollView.delegate = self;
        self.myScrollView.maximumZoomScale=3.0;//最大倍率（默认倍率）
        self.myScrollView.minimumZoomScale=1.0;//最小倍率（默认倍率）
        self.myScrollView.decelerationRate=1.5;//减速倍率（默认倍率）
        _myScrollView.pagingEnabled = YES;
        [self.contentView addSubview:self.myScrollView];
        
        self.myImage = [[UIImageView alloc] initWithFrame:self.myScrollView.bounds];
        self.myImage.backgroundColor = [UIColor blackColor];
        self.myImage.contentMode =  UIViewContentModeScaleAspectFit;
        self.myImage.userInteractionEnabled = YES;
        _myImage.clipsToBounds = YES;
        [self.myScrollView addSubview:self.myImage];
        
        
        //双击缩小手势
        UITapGestureRecognizer *tapAC = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionRestore:)];
        // 要求轻拍两下触发
        tapAC.numberOfTapsRequired = 2;
        [self.myScrollView addGestureRecognizer:tapAC];
        
    }
    return self;
}

//双击恢复图片的方法
- (void)tapActionRestore:(UITapGestureRecognizer *)tap
{
    [self.myScrollView setZoomScale:1.0f animated:YES];
}

//放大视图的方法
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return [scrollView.subviews firstObject];
}

@end
